<?php
$redis = new \redis();
$redis->connect('127.0.0.1', 6379);
//$redis->auth('admin2020');
//查询库存
if($redis->lLen('goods_list') == 0)
    echo '商品已售完...\n';
$uid = $_SERVER['REMOTE_PORT'];
//查询是否购买过
if($redis->sIsMember('bought_list',$uid))
     echo '你已经购买过了!\n';
$goods_id = $redis->rpop('goods_list');
$redis->sAdd('bought_list',$uid);
$value = array(
    'uid'   =>  $uid,
    'goods_id'   =>  $goods_id,
    'time'  =>  time(),
);
$redis->hSet('order_info',$uid,json_encode($value));
echo '购买成功。\n';
